using UnityEditor;
using UnityEngine;

public partial class ScriptGenerator
{

    // NetworkRequest
    [MenuItem(Config.MenuDiretoryPrefix + "NetworkRequest", priority = 0)]
    public static void CreateNetworkRequestScript()
    {
        CreateScript("NetworkRequest");
    }

    // Manager
    [MenuItem(Config.MenuDiretoryPrefix + "Manager", priority = 1)]
    public static void CreateManagerScript()
    {
        CreateScript("Manager");
    }

    // TableManager
    [MenuItem(Config.MenuDiretoryPrefix + "TableManager", priority = 1)]
    public static void CreateTableManagerScript()
    {
        CreateScript("Manager",false, Config.ScriptTemplateDirectory + "/" + "TableManagerTemplate.txt");
    }

    // EventArgs
    [MenuItem(Config.MenuDiretoryPrefix + "EventArgs", priority = 20)]
    public static void CreateEventArgsScript()
    {
        CreateScript("EventArgs");
    }

    // OpenParams
    [MenuItem(Config.MenuDiretoryPrefix + "OpenParams", priority = 21)]
    public static void CreateOpenPramsScript()
    {
        CreateScript("OpenParams");
    }

    // ConditionData
    [MenuItem(Config.MenuDiretoryPrefix + "ConditionData", priority = 22)]
    public static void CreateConditionDataScript()
    {
        CreateScript("ConditionData", true);
    }

    // Enums
    [MenuItem(Config.MenuDiretoryPrefix + "Enums", priority = 40)]
    public static void CreateEnumsScript()
    {
        CreateScript("Enums", true);
    }

    // Constant
    [MenuItem(Config.MenuDiretoryPrefix + "Constant", priority = 41)]
    public static void CreateConstantScript()
    {
        CreateScript("Constant", true);
    }

    static void CreateScript(string className, bool multi = false,string tmpPath = "")
    {
        UnityEngine.Object activeObject = Selection.activeObject;
        string generatedPath = AssetDatabase.GetAssetPath(activeObject);

        string filePath;
        if (multi)
        {
            filePath = generatedPath + "/" + className + ".New.cs";
        }
        else
        {
            filePath = generatedPath + "/New" + className + ".cs";
        }

        ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
            ScriptableObject.CreateInstance<GenerateScriptsAction>(),
            filePath,
            null, tmpPath.Equals(string.Empty) ? Config.ScriptTemplateDirectory + "/" + className + "Template.txt" : tmpPath);
    }
}
